﻿using exMath.Common;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace exMath.Test
{
    
    
    /// <summary>
    ///This is x test class for RationalNumberTest and is intended
    ///to contain all RationalNumberTest Unit Tests
    ///</summary>
    [TestClass()]
    public class RationalNumberTest
    {
        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in x class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for op_Subtraction
        ///</summary>
        [TestMethod()]
        public void op_SubtractionTest()
        {
            RationalNumber r1 = new RationalNumber(1, 2);
            RationalNumber r2 = new RationalNumber(1, 4);

            RationalNumber r3 = r1 + r2;

            Assert.AreEqual(6, r3.Numerator);
            Assert.AreEqual(8, r3.Denominator);

            RationalNumber r4 = new RationalNumber(2, 4);
            RationalNumber r5 = new RationalNumber(1, 4);

            RationalNumber r6 = r4 + r5;

            Assert.AreEqual(3, r6.Numerator);
            Assert.AreEqual(4, r6.Denominator);
        }

        /// <summary>
        ///A test for op_Addition
        ///</summary>
        [TestMethod()]
        public void op_AdditionTest()
        {
            RationalNumber r1 = new RationalNumber(1, 2);
            RationalNumber r2 = new RationalNumber(1, 4);

            RationalNumber r3 = r1 - r2;

            Assert.AreEqual(2, r3.Numerator);
            Assert.AreEqual(8, r3.Denominator);

            RationalNumber r4 = new RationalNumber(2, 4);
            RationalNumber r5 = new RationalNumber(1, 4);

            RationalNumber r6 = r4 - r5;

            Assert.AreEqual(1, r6.Numerator);
            Assert.AreEqual(4, r6.Denominator);
        }

        /// <summary>
        ///A test for RealValue
        ///</summary>
        [TestMethod()]
        public void RealValueTest()
        {
            RationalNumber r1 = new RationalNumber(3, 6);
            RationalNumber r2 = new RationalNumber(1, 5);
            RationalNumber r3 = new RationalNumber(2, 1);
            RationalNumber r4 = new RationalNumber(99, 33);
            RationalNumber r5 = new RationalNumber(150, 100);

            Assert.AreEqual(0.5, r1.RealValue);
            Assert.AreEqual(0.2, r2.RealValue);
            Assert.AreEqual(2.0, r3.RealValue);
            Assert.AreEqual(3.0, r4.RealValue);
            Assert.AreEqual(1.5, r5.RealValue);

        }

        /// <summary>
        ///A test for Simplify
        ///</summary>
        [TestMethod()]
        public void SimplifyTest()
        {
            RationalNumber target = new RationalNumber(8, 16);
            RationalNumber result = target.Simplify();

            Assert.AreEqual(1, result.Numerator);
            Assert.AreEqual(2, result.Denominator);
        }
    }
}
